<template>
  <div class="c-bg-sgray">
    <template>
      <div class="c-bg-white c-ph24 c-pv12 c-flex-row c-justify-sb c-aligni-center">
        <div class="c-fs26 c-fc-xblack c-fw500">同意隐私政策</div>
        <x-switch :themeColor="$getThemeColor()" title="" v-model="agreePrivacy" prevent-default @on-click="changePrivacySwitch" :value-map="[0, 1]"></x-switch>
      </div>
      <div class="c-ph24 c-pv30 c-fs22 c-fc-gray">
        <div>隐私政策说明：在您使用app的过程中，系统需要收集您的个人信息以保证服务能正常运行。若您希望撤回对隐私协议的同意，请点击上方按钮关闭“同意隐私政策”，系统将不再搜集您的个人信息，<span class="c-fc-red">但同时您将无法再使用app相关功能，除非您再次同意政策。</span></div>
        <div>隐私政策详情请查阅<span class="c-fc-mblue" @click="linkToProtocol(protocolInfo.privacyProtocolUrl)">《隐私政策》</span></div>
      </div>
    </template>
  </div>
</template>
<script>
import { XSwitch } from 'ckjrweb-mp-ui/src/components/index';
import { utilJs } from "@/utils/common.js";
// let imgData = {};
// let serverIdImgArr = [];
export default {
  name: "PrivacySettingIndex",
  components: {
    XSwitch
  },
  created() {
    utilJs.appShare(this);
  },
  data() {
    return {
      theme: localStorage.getItem("colorName") || "mb5_default",
      // personalizedService: 1,
      agreePrivacy: 1,
      protocolInfo: null
    };
  },
  methods: {
    changePrivacySwitch() {
      if (this.agreePrivacy == 1) {
        this.agreePrivacy = 0;
        window.localStorage.clear();
        if (utilJs.isIOSApp()) {
          window.webkit.messageHandlers.iosWechatLoginOut.postMessage('loginOut');
        } else {
        utilJs.androidAppExit();
        }
      }
    },
    //分享
    wechatShare: function () {
      let title = '隐私设置' || window.localStorage.getItem("shareTitle");
      let shareUrl =
        window.location.href.split("#")[0] +
        "#" +
        this.$route.path +
        "?refereeId=" +
        localStorage.getItem("userId");
      utilJs.wechatConfig(
        shareUrl,
        title,
        "",
        "",
        function () { },
        true
      );
    },
    //手机端分享
    appShare() {
      let title = '隐私设置' || window.localStorage.getItem("shareTitle");
      let shareUrl =
        window.location.href.split("#")[0] +
        "#" +
        this.$route.path +
        "?refereeId=" +
        localStorage.getItem("userId");
      utilJs.appShareTrue(title, "", shareUrl, "");
    },
    linkToProtocol(url) {
      if (!url) return
      window.location.href = url;
    },
    getAppUseAndPrivacyProtocols() {
      utilJs.getMethod(`${global.apiurl}app/getAppUseAndPrivacyProtocols`, (res) => {
        this.protocolInfo = res || null;
      });
    },
  },
  activated() {
    setDocumentTitle("设置");// eslint-disable-line
    this.agreePrivacy = 1;
    // this.personalizedService = localStorage.getItem("personalizedService") ? Number(localStorage.getItem("personalizedService")) : 1;
    this.wechatShare();
    this.getAppUseAndPrivacyProtocols()
  },
  deactivated() {
  }
};
</script>
<style scoped>
</style>